package com.threeti.mecool.core.domain.model.acl;

import java.util.Collections;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import com.threeti.jiayusms.framework.domain.support.DefaultDomainEntity;
import com.threeti.jiayusms.framework.util.Lists;

/** (明酷督导管理系统)用户 */
@Entity
@Table(name = "DM_USER")
public class User extends DefaultDomainEntity {
	
//	private User parentUser;
//	
//	private List<User> childUsers;
//	
//  private OrgnizationLegacy orgnization;

  @ManyToMany(cascade=CascadeType.ALL,fetch=FetchType.EAGER)
  @JoinTable(name = "DM_USER_ROLE", joinColumns = { @JoinColumn(name = "USER_ID") }, inverseJoinColumns = { @JoinColumn(name = "ROLE_ID") })
  @Fetch(FetchMode.SUBSELECT)
  private List<Role> roles = Lists.newArrayList();
	
	private String empNo;

  @Column(nullable = false, unique = true)
  private String loginName;
  
  private String displayName;

  @Column(nullable = false)
  private String password;

  @Enumerated(EnumType.ORDINAL)
  private UserStatus status = UserStatus.PENDING;
  
  public List<Role> getRoles() {
    return Collections.unmodifiableList(roles);
  }

  public String getEmpNo() {
    return empNo;
  }

  public String getLoginName() {
    return loginName;
  }

  public String getDisplayName() {
    return displayName;
  }

  public String getPassword() {
    return password;
  }

  public UserStatus getStatus() {
    return status;
  }

  public User() {
    super();
  }

  public User(String loginName, String displayName, String password) {
    this.loginName = loginName;
    this.displayName = displayName;
    this.password = password;
  }
  
  
}
